package com.zrrd.yt.product.controller;

import com.zrrd.yt.common.result.Result;
import com.zrrd.yt.model.product.BaseAttrInfo;
import com.zrrd.yt.model.product.BaseAttrValue;
import com.zrrd.yt.product.service.BaseAttrService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/product")
public class BaseAttrController {

    @Autowired
    private BaseAttrService baseAttrService;

    //查询平台属性
    @GetMapping("/attrInfoList/{category1Id}/{category2Id}/{category3Id}")
    public Result<List<BaseAttrInfo>> attrInfoList(@PathVariable("category1Id") Long category1Id,
                                                   @PathVariable("category2Id") Long category2Id,
                                                   @PathVariable("category3Id") Long category3Id){
        return Result.ok(baseAttrService.selectBaseAttrInfoList(category1Id,category2Id,category3Id));
    }

    //添加、修改平台属性
    @PostMapping("/saveAttrInfo")
    public Result<String> saveAttrInfo(@RequestBody BaseAttrInfo baseAttrInfo){
        baseAttrService.saveBaseAttrInfo(baseAttrInfo);
        return Result.ok("成功");
    }

    //根据属性ID获取属性以及属性值
    @GetMapping("/getAttrValueList/{attrId}")
    public Result<List<BaseAttrValue>> getAttrValueList(@PathVariable("attrId") Long attrId){
        return Result.ok(baseAttrService.getAttrInfo(attrId));
    }


}
